<?php 
class Email{
  public  function sendMailInternal($name='', $email, $subject, $content, $is_html = 0, $need_bcc = true, $from = null)
    {
        $mail = new Zend_Mail('UTF-8');
        $mail->setSubject(self::encodeBase64($subject));
        if (!is_null($from)) {
            $mail->setFrom($from['sender_email'], $from['sender_name']);
        } else {
            $mail->setFrom($GLOBALS['smtp_user'], self::encodeBase64($GLOBALS['shop_name']));
        }
        if ($GLOBALS['smtp_user'] != $GLOBALS['smtp_mail']) {
            $mail->addHeader('Reply-to', self::encodeBase64('"' . $GLOBALS['shop_name']. '"') . ' <' . $GLOBALS['smtp_mail'] . '>', true);
        }
        $mail->addTo($email, $name);
        if ($need_bcc && !empty($GLOBALS['bcc_list'])) {
            foreach ($GLOBALS['bcc_list'] as $bcc) {
                $mail->addBcc($bcc['email'], self::encodeBase64($bcc['name']));
            }
        }
        if ($is_html == 0) {
            $mail->setBodyText($content, 'UTF-8', Zend_Mime::ENCODING_BASE64);
        } else {
            $mail->setBodyHtml($content, 'UTF-8', Zend_Mime::ENCODING_BASE64);
        }
        $config = array();
        $config['auth'] = 'login';
        $config['name'] = $GLOBALS['smtp_host'];
        $config['port'] = $GLOBALS['smtp_port'];
        $config['username'] = $GLOBALS['smtp_user'];
        $config['password'] = $GLOBALS['smtp_pass'];
        
        if (!empty($GLOBALS['smtp_ssl'])) {
            $config['ssl'] = $GLOBALS['smtp_ssl'];
        }
        
        try {
        	$transport = new Zend_Mail_Transport_Smtp($GLOBALS['smtp_host'], $config);
        	$mail->send($transport);
        }
        catch (Exception $e)
        {
        	return false;
        }
        
        return true;
        
    }

    private static function encodeBase64($str)
    {
        return '=?UTF-8?B?' . base64_encode($str) . '?=';
    }
}
?>
